/**
 *******************************************************************************
 * @FileName  : pwm.c
 * @Author    : GaoQiu
 * @CreateDate: 2020-05-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 */
#include "pwm.h"
#include "platform/platform.h"

#define GPIOx     GPIOA
#define PWM_PIN   GPIO_Pin_2

void PWM_SetUp(void)
{
	/* Enable PWM clock. */
	RCC_EnablePeriphClk(RCC_PWM);

	/* GPIO config. */
	GPIO_InitType_t GPIO_InitStruct;
	GPIO_InitStruct.GPIO_Pin  = PWM_PIN;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_Out;
	GPIO_InitStruct.GPIO_Pull = GPIO_Pull_Floating;
	GPIO_Init(GPIOx, &GPIO_InitStruct);

	/* Set GPIO alternative function. */
	GPIO_SetAlternFunc(GPIOx, PWM_PIN, GPIO_AF_PWM0);

	/* Set PWM. */
	PWM_Init(0);
	PWM_SetMode(PWM0, PWM_MODE_NORMAL);
	PWM_SetPulse(PWM0, 48, 48*2);
	PWM_SetPulseNum(PWM0, 100);
	PWM_Enable(PWM0);

//	uint16_t irData[]={
//		40,    0,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//		0x8fff, 0x0fff,
//	};

	//PWM_DmaSetData(irData, sizeof(irData));
	//PWM_DmaEnable();
}

void PWM_Loop(void)
{

}
